package com.lms.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-05-18 07:21
 * @Description: ${Description}
 */
public class ProxyFactory {

    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object getProxyInstance(){
        ClassLoader classLoader = target.getClass().getClassLoader();
        Class<?>[] interfaces = target.getClass().getInterfaces();
        InvocationHandler invocationHandler = (proxy, method, args) -> {
            System.out.println("执行的方法："+method.getName());
            Object invoke = method.invoke(target, args);
            return invoke;
        };
        Object proxyInstance = Proxy.newProxyInstance(classLoader, interfaces, invocationHandler);
        return proxyInstance;
    }
}
